// 
// task.h - Defines the structures and prototypes needed to multitask.
//          Written for JamesM's kernel development tutorials.
//

#ifndef TASK_H
#define TASK_H

#include "common.h"
#include "paging.h"

#define T_STARTING  0
#define T_IDLE		1
#define T_RUNNING	2
#define T_DEAD		3

// This structure defines a 'task' - a process.
typedef struct task
{
    int id;                // Process ID.
    u32int esp, ebp;       // Stack and base pointers.
    u32int eip;            // Instruction pointer.
    page_directory_t *page_directory; // Page directory.
	int t_state;
    struct task *next;     // The next task in a linked list.
} task_t;

// The start of the task linked list.
volatile task_t *ready_queue;
// The currently running task.
volatile task_t *current_task;
// Initialises the tasking system.
void initialise_tasking();

// Called by the timer hook, this changes the running process.
void task_switch();

// Forks the current process, spawning a new one with a different
// memory space.
int fork();

// Causes the current process' stack to be forcibly moved to a new location.
void move_stack(void *new_stack_start, u32int size);

// Returns the pid of the current process.
int getpid();
void thread_create(void (*func)(void*), void *arg);
void thread_list();
int task_from_pid(int pid);
#endif
